package models

import "time"

type Transaction struct {
	ID          uint      `gorm:"primaryKey" json:"id"`
	AccountID   uint      `gorm:"not null;index" json:"account_id"`
	Type        string    `gorm:"type:enum('deposit','withdraw');not null" json:"type"`
	Amount      float64   `gorm:"type:decimal(18,2);not null" json:"amount"`
	OperatorID  uint      `gorm:"not null" json:"operator_id"`
	Remark      string    `gorm:"size:255" json:"remark"`
	CreatedTime time.Time `gorm:"autoCreateTime" json:"created_time"`
}

func GetTransactionsByAccount(accountID uint) ([]Transaction, error) {
	var txs []Transaction
	if err := DB.Where("account_id = ?", accountID).Find(&txs).Error; err != nil {
		return nil, err
	}
	return txs, nil
}
